package com.huilian.iotbox.client.controller;

import com.alibaba.fastjson.JSON;
import com.huilian.iotbox.client.security.jwt.util.JwtTokenUtil;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.dto.MemberDto;
import com.huilian.iotbox.data.service.UploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author: loong
 * @create: 2023-03-31 18:12
 **/
@Slf4j
@RestController
@RequestMapping("/api/upload")
public class uploadController extends BaseController {
    @Resource
    private JwtTokenUtil jwtTokenUtil;
    @Resource
    private UploadService uploadService;

    @PostMapping("/uploadImage")
    public ServerResponse uploadImageToFTP(@RequestBody MultipartFile image, HttpServletRequest request) throws Exception {
        MemberDto memberDto = jwtTokenUtil.getMemberFromReq(request);
        log.info("uploadImageToFTP" + JSON.toJSONString(memberDto));
        return uploadService.uploadImageToFTP(image.getInputStream());
    }
}
